using System;
using System.Windows.Forms;
using Slf.Formatters;

namespace Slf.Samples.ConditionalLoggers
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
      InitLoggers();
    }


    private void InitLoggers()
    {
      //The sample uses two different DelegateLogger implementations for simplicity.
      //switch between Debug/Release builds to change the logger that is actually assigned.

#if DEBUG
      ILogger logger = new DelegateLogger(LogInDebugBuild);
      LoggerService.SetLogger(logger);
#else
      ILogger logger = new DelegateLogger(LogInReleaseBuild);
      LoggerService.SetLogger(logger);
#endif
    }



    //Displays logged data through a message box
    private void LogInReleaseBuild(LogItem item)
    {
      MessageBox.Show(item.Message);
    }


    //Displays logged data in the form's textbox
    private void LogInDebugBuild(LogItem item)
    {
      txtDebugOutput.Text = SimpleLogItemFormatter.Instance.FormatItem(item);
    }


    //creates a log entry
    private void button1_Click(object sender, EventArgs e)
    {
      ILogger logger = LoggerService.GetLogger();
      logger.Info("You clicked the button at {0}", DateTime.Now.TimeOfDay);
    }
  }
}